package lancooUpLoad;

import com.example.hyznbk.presenter.PaperDef;
import com.example.hyznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.hyznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import testPaperWrong.WrongQuesPaperActivity;

/**
 * Created by Administrator on 2017/9/5/005.
 */

public class SaveZsdPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private boolean isFromExit = false;

    public SaveZsdPresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        //  if (isShowLoading) view.showLoading();
        HttpOnNextListener<String> httpOnNextListener = new HttpOnNextListener<String>() {


            @Override
            public void onNext(String saveZsdEntityResult) {
                if(saveZsdEntityResult.equals("true")){

//                    if (isFromExit){
//                        ToastUtils.showShort("数据保存成功");
//                        new Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//
//                            }
//                        },600);

//                    }
                }else{
//                    ToastUtils.showShort("数据保存失败! 错误信息"+saveZsdEntityResult);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                //view.showNetError();
                ToastUtils.showShort("数据保存失败!");
            }
        };

        SaveZsdParam api = null;
        if(ModelFrom == PaperDef.FROM_BASE_REVIEW) {

        }else if(ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
            api = new SaveZsdParam(httpOnNextListener, (WrongQuesPaperActivity)view);
        }else if(ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW){

        }else if(ModelFrom == PaperDef.FROM_GUESS_REVIEW){
        }

        api.setSaveLearnedZsd(DataPackage.saveLearnedZSD(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,UserInfo.StuName,
                PaperInfor.ZSDName,PaperInfor.ZSDCode));
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}